package scripts.sea;

import api.sea.DelegationApi;
import api.sea.LoginApi;
import api.sea.StayPreplanApi;
import api.sea.StayStuffApi;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import util.AssertUtil;
import util.HttpClientUtils;
import util.ResponseData;

import java.io.IOException;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 待预配列表
 */
public class TestStayPreplan {
    private final StayPreplanApi stayPreplanApi=new StayPreplanApi();
    private String id;
    private String code;
    private static final Logger logger= LoggerFactory.getLogger(TestStayPreplan.class);
    @Test
    public void test_01() throws IOException, URISyntaxException {
        ResponseData responseData = LoginApi.login("admin", "qf123456?");
        String data = responseData.getBody().getJSONObject("data").getString("logistics-token");
        HttpClientUtils.build_header("logistics-token",data);
        HttpClientUtils.build_header("Content-Type","application/json");
    }
    @Test
    public void test_02() throws IOException, URISyntaxException {
        JSONArray data=new JSONArray();
        Map<String,String> map_data=new HashMap<>();
        map_data.put("cartons","1");
        map_data.put("length","1");
        map_data.put("width","1");
        map_data.put("mark","Tokyo  Hot");
        map_data.put("weight","1");
        data.add(map_data);
        Date date=new Date();
        SimpleDateFormat time=new SimpleDateFormat("HH:mm:ss");
        String s=time.format(date);
        String date_time="QFHY-"+s;
        ResponseData responseData= DelegationApi.delegation("TCY179310074272899092",
                "COOLPAI",""+date_time,
                0,"",data,"2021-03-22",
                "LIANYUNGANG","CHICAGO","pingming","2021-04-06","3",
                ""+date_time,
                "1","LWL"+s,
                "100","1","0","","","","",
                1,1,1,
                "","","US","","","","","Tokyo  Hot","",
                "",""+date_time,
                "6","1","0",0,"王晓亮","5409d88922bf4d5187f4",
                "7cd6188ea979499e892e","黄德挺",
                "7cd6188ea979499e892e","黄德挺","创实",
                "CU163032594897092663",2);
        this.id=responseData.getBody().getJSONObject("data").getString("id");
        code=responseData.getBody().getJSONObject("data").getString("entrustmentCode");
        code=responseData.getBody().getJSONObject("data").getString("entrustmentCode");
        logger.info("id={}",id);

    }
    @Test
    public void test_03() throws IOException, URISyntaxException {
        ResponseData responseData = StayStuffApi.stay_stuff(this.id);
        logger.info("委托单响应体数据={}", responseData.getBody());
    }
    @Test
    public void test_04() throws IOException, URISyntaxException {
        String number= RandomStringUtils.randomNumeric(8);
        ResponseData responseData=stayPreplanApi.stay_preplan(this.code,this.id,number,1,"1.00","1.00","LIANYUNGANG",
                "CHICAGO","2","4","1","2021-03-24","2021-03-25",1);
        AssertUtil.assertCommon(responseData,0,"成功");
    }

}
